/*
 *    Copyright (c) 2018-2025, daoism All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: daoism
 */
package com.mkh.st.admin.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mkh.st.admin.api.dto.StFinancialSetDTO;
import com.mkh.st.admin.api.entity.StFinancialSet;
import com.mkh.st.admin.mapper.StFinancialSetMapper;
import com.mkh.st.admin.service.StFinancialSetService;
import com.mkh.st.common.core.constant.CommonConstants;
import com.mkh.st.common.security.util.SecurityUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import javax.smartcardio.CommandAPDU;

/**
 * 财务配置表
 *
 * @author daoism code generator
 * @date 2021-09-27 15:03:10
 */
@Service
@AllArgsConstructor
public class StFinancialSetServiceImpl extends ServiceImpl<StFinancialSetMapper, StFinancialSet> implements StFinancialSetService {

	private final StFinancialSetMapper financialSetMapper;

	@Override
	public Boolean financialSetSave(StFinancialSetDTO dto) {
		StFinancialSet financialSet= BeanUtil.toBean(dto,StFinancialSet.class);
		if(ObjectUtil.isNotNull(dto.getId())){
			financialSetMapper.updateById(financialSet);
		}else {
			financialSet.setDelFlag(CommonConstants.ZERO);
			financialSet.setTenantId(SecurityUtils.getUser().getTenantId());
			financialSetMapper.insert(financialSet);
		}
		return Boolean.TRUE;
	}

	@Override
	public StFinancialSet getFinancialSet() {
		StFinancialSet financialSet=financialSetMapper.selectOne(Wrappers.<StFinancialSet>lambdaQuery()
			.eq(StFinancialSet::getDelFlag,CommonConstants.ZERO)
			.eq(StFinancialSet::getTenantId,SecurityUtils.getUser().getTenantId()));
		return financialSet;
	}
}
